package com.ey12.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.ey12.db.dao.GmAccessDAO;
import com.ey12.db.dao.GmCserverDAO;
import com.ey12.db.dao.GmGameDAO;
import com.ey12.db.dao.GmGameStoreDAO;
import com.ey12.db.domain.GmAccess;
import com.ey12.db.domain.GmCp;
import com.ey12.db.domain.GmCserver;
import com.ey12.db.domain.GmGame;
import com.ey12.db.domain.GmGameStore;
import com.ey12.db.domain.GmNews;
import com.ey12.db.domain.GmOrder;
import com.ey12.db.domain.GmUser;
import com.ey12.utils.DateUtil;

public class GmGameService {
	private GmGameDAO gmGameDAO;
	private GmCserverDAO gmCserverDAO;
	private GmGameStoreDAO gmGameStoreDAO;
	private GmAccessDAO gmAccessDAO;
	public void setGmGameDAO(GmGameDAO gmGameDAO) {
		this.gmGameDAO = gmGameDAO;
	}

	public GmGameDAO getGmGameDAO() {
		return gmGameDAO;
	}
	public List getALl() {
		List list = gmGameDAO.findAll();
		System.out.println("GmGameService=" + list.size());
		return list;
	}
	
	public void delGame(GmGame g){
		gmGameDAO.delete(g);
	}
	public void saveGame(GmGame g) {
		g.setId(null);
		gmGameDAO.saveOrUpdate(g);
	}
	public void updateGame(GmGame g) {
		gmGameDAO.saveOrUpdate(g);
	}
	
	public List getHotGameList() {
		List result = new ArrayList();
		List list = gmGameDAO.findHotGameList();
		if (list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				if (i > 5) {
					break;
				}
				GmGame gm = (GmGame) list.get(i);
				result.add(gm);
			}
		}
		System.out.println("GmGameService=" + result.size());
		return result;
	}
	public List getbvwData() {
//		List result = new ArrayList();
		List list = gmGameDAO.findbvwData();
//		if (list.size() > 0) {
//			for (int i = 0; i < list.size(); i++) {
//				GmGame gm = (GmGame) list.get(i);
//				result.add(gm);
//			}
//		}
		System.out.println("getbvwData=" + list.size());
		return list;
	}
	public void setGmCserverDAO(GmCserverDAO gmCserverDAO) {
		this.gmCserverDAO = gmCserverDAO;
	}

	public GmCserverDAO getGmCserverDAO() {
		return gmCserverDAO;
	}

	public List getFirstCbx() {
		List list = gmGameDAO.findFirstCbx();
		if (list.size() > 0) {
			return list;
		}
		return null;
	}

//	public List getSellViewFirstCbx(String username) {
//		System.out.println("getSellViewFirstCbx() used");
//		List list = gmAccessDAO.findSellViewFirstCbx(username);
//		System.out.println(list.size());
//		if (list.size() > 0) {
//			System.out.println("getSellViewFirstCbx()="+list.size());
//			return list;
//		}
//		return null;
//	}
//	public List getSellViewSecondCbx(String username,String gameName) {
//		List games = gmAccessDAO.findSellViewSecondCbx(username,gameName);
//		if (games.size() > 0) {
//			return games;
//		}
//		return null;
//	}
	public Set getSecondCbx(String gameName) {
		List games = gmGameDAO.findByGameName(gameName);
		if (games.size() > 0) {
			GmGame game = (GmGame) games.get(0);
			System.out.println("game.getGmCservers()="+game.getGmCservers().size());
			return game.getGmCservers();
		}
		return null;
	}


//	public List getThirdCbx(String cserverName) {
//		List list = gmCserverDAO.findThirdCbxByCname(cserverName);
//		if (list.size() > 0) {
//			return list;
//		}
//		return null;
//	}
//
//	public List getLastCbx(String severType) {
//		List list = gmCserverDAO.findLastsCbxByStype(severType);
//		if (list.size() > 0) {
//			return list;
//		}
//		return null;
//	}

	public Set getGameDetial(String gameName) {
		List games = gmGameDAO.findByGameName(gameName);
		if (games.size() > 0) {
			GmGame game = (GmGame) games.get(0);
			System.out.println("game.getGmGameStores()="+game.getGmGameStores().size());
			return game.getGmGameStores();
		}
		return null;
	}
//	public Set getGameDetialData(String gameName,String cserverName,String serverType,String camp) {
//		List games = gmCserverDAO.findGameDetialData(gameName,cserverName,serverType,camp);
//		if (games.size() > 0) {
//			GmCserver game = (GmCserver) games.get(0);
//			System.out.println("game.getGmGameStores()="+game.getGmGameStores().size());
//			return game.getGmGameStores();
//		}
//		return null;
//	}
	
//	public List findGoodData(GmUser guser) {
//		List result = new ArrayList();
////		String userName = guser.getUserName();
//		List list = gmGameStoreDAO.findGood(guser.getUserName());
//		if (list.size() > 0) {
//			for (int i = 0; i < list.size(); i++) {
//				GmCserver gm = (GmCserver) list.get(i);
//				result.add(gm);
//			}
//		}
//		System.out.println(result.size());
//		return result;
//	}
	
//	public void addNewGood(GmGameStore game) {
//		GmGameStore cp = new GmGameStore();
//		cp.setGmUser(game.getGmUser());
//		cp.getGmGame().setGameName(game.getGmGame().getGameName());
//		cp.getGmCserver().setCserverName(game.getGmCserver().getCserverName());
//		cp.getGmCserver().setSeverType(game.getGmCserver().getSeverType());
//		cp.getGmCserver().setUnit(game.getGmCserver().getUnit());
//		cp.setPrice(game.getPrice());
//		cp.setStoreNum(game.getStoreNum());
//		cp.setLeastMount(game.getLeastMount());
//		cp.setIsDeposit(game.getIsDeposit());
//		cp.setIsQuick(game.getIsQuick());
//		cp.setUpdateDate(new DateUtil().toDateString());
//		gmGameStoreDAO.saveOrUpdate(cp);
//	}
	
	
	public void setGmGameStoreDAO(GmGameStoreDAO gmGameStoreDAO) {
		this.gmGameStoreDAO = gmGameStoreDAO;
	}

	public GmGameStoreDAO getGmGameStoreDAO() {
		return gmGameStoreDAO;
	}

	public void setGmAccessDAO(GmAccessDAO gmAccessDAO) {
		this.gmAccessDAO = gmAccessDAO;
	}

	public GmAccessDAO getGmAccessDAO() {
		return gmAccessDAO;
	}
}
